package com.crm.utils;

import com.crm.domain.entity.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Objects;

/**
 * 当前登录用户信息工具类
 *
 * @author wb
 * @since 2025-01-15
 */
public class SecurityHolderUtil {


    /**
     * 获取当前登录用户信息
     *
     * @return 用户信息
     */
    public static User  getUser() {
        HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        HttpSession session = request.getSession();
        return (User) session.getAttribute("session_user");
    }
}
